<template>
    <rx-layout>
        <div slot="center" style>
            <rx-fit>
                <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
                    <rx-list-title :title="i18n('list.asyncDown','异步下载')"></rx-list-title>
                    <div class="table-operator">
                        <rx-button v-show="selectedRowKeys && selectedRowKeys.length>0" alias="formExcelGenTaskDelete" butn-icon="delete" butn-type="danger"
                                   :show-no-right="false" @click="delByIds(selectedRowKeys)">{{$ti18('rxList.delBtn','删除')}}
                        </rx-button>
                    </div>
                    <span class="search-btn-box">
                        <span class="search-btn" @click="searchshow"><i class="iconfont iconguolv"></i>{{$ti18('rxList.leachBtn','过滤')}}</span>
                   </span>
                </div>
                <div slot="searchbar" btnalign="right" v-if="fitSearch" @search="search" @cancel="cancel"
                     @close="close">
                    <a-form layout="vertical">
                        <a-form-item :label="i18n('form.fileName','文件名称')">
                            <a-input :placeholder="i18n('form.fileName','文件名称','input')" v-model="queryParam.Q_FILE_NAME__S_LK"/>
                        </a-form-item>
                    </a-form>
                    <a-form layout="vertical">
                        <a-form-item :label="i18n('form.ownerName','所属列表')">
                            <a-input :placeholder="i18n('form.ownerName','请输入所属列表','input')" v-model="queryParam.Q_LIST_NAME__S_LK"/>
                        </a-form-item>
                    </a-form>
                </div>
                <rx-grid
                    ref="table"
                    :bordered="isBorder"
                    :allowRowSelect="true"
                    :multiSelect="true"
                    :columns="columns"
                    :defaultPageSize="10"
                    url="/api-form/form/core/formExcelGenTask/query"
                    :queryParam="queryParam"
                    data-field="result.data"
                    :pageSizeOptions="['10','30','40']"
                    id-field="id"
                    @selectChange="onSelectChange"
                >
                    <span slot="remark" slot-scope="{ text, record }">
                        {{getRemark(record)}}
                    </span>
                    <span slot="fileName" slot-scope="{ text, record }">
                        <a @click.stop="downloadExcel(record)">{{text}}</a>
                    </span>
                    <span slot="genStatus" slot-scope="{ text, record }">
                        <a-tag :color="statusMap[text].color">
                            <span>{{ statusMap[text].text }}</span>
                        </a-tag>
                    </span>
                    <span slot="action" slot-scope="{ text, record }" class="actionIcons">
                        <span v-show="record.fileId" @click.stop="downloadExcel(record)">{{$ti18('rxList.download','下载')}}</span>
                        <span v-show="record.fileId" @click.stop="getDownloadRecord(record)">{{i18n('list.record','下载记录')}}</span>
                        <span @click.stop="delByIds([record.id])">{{$ti18('rxList.delBtn','删除')}}</span>
                    </span>
                </rx-grid>
            </rx-fit>
            <a-drawer
                :title="i18n('list.record','下载记录')"
                placement="right"
                :closable="true"
                :visible="visible"
                @close="onClose"
                :maskClosable="true"
                :destroyOnClose="true"
                width="400"
            >
               <FormDownloadRecordList :selectGenTaskId="selectGenTaskId" ></FormDownloadRecordList>
            </a-drawer>
        </div>
    </rx-layout>
</template>

<script>
import FormExcelGenTaskApi from '@/api/form/core/formExcelGenTask'
import FormExcelGenTaskEdit from './FormExcelGenTaskEdit'
import FormDownloadRecordList from './FormDownloadRecordList'
import {BaseList, RxFit, RxGrid,TokenUtil} from "@lowcode/jpaas-common-lib";

export default {
    name: 'FormExcelGenTaskList',
    mixins: [BaseList],
    components: {
        RxFit,
        FormDownloadRecordList
    },
    data() {
        return {
            columns: [
                {
                    title: this.$ti18('rxList.index','序号'),
                    type: 'indexColumn',
                    width: 40,
                    dataIndex: 'serial',
                    scopedSlots: {customRender: 'serial'}
                },
                {title: this.i18n('form.fileName','文件名称'), dataIndex: 'fileName', width: 100, scopedSlots: {customRender: 'fileName'}},
                {title: this.i18n('form.owner','所属人'), dataIndex: 'createByName', width: 100},
                {title: this.i18n('form.createTime','生成时间'), dataIndex: 'createTime', width: 100},
                {title: this.i18n('form.status','状态'), dataIndex: 'genStatus', width: 100, scopedSlots: {customRender: 'genStatus'}},
                {title: this.i18n('form.ownerName','所属列表'), dataIndex: 'listName', width: 100},
                {title: this.i18n('form.remarks','备注'), dataIndex: 'remark', width: 100, scopedSlots: {customRender: 'remark'}},
                {title: this.$ti18('rxList.action','操作'), width: 120, dataIndex: 'action', scopedSlots: {customRender: 'action'}}
            ],
            component: FormExcelGenTaskEdit,
            comment: this.i18n('list.comment','Excel生成任务'),
            widthHeight: ['800px', '600px'],
            fitSearch: false,
            visible:false,
            //选择的任务ID
            selectGenTaskId:"",
            statusMap: {
                0: {color: 'red', text: this.i18n('statusMap.failure','生成失败')},
                1: {color: 'green', text: this.i18n('statusMap.success','生成成功')},
                2: {color: 'blue', text: this.i18n('statusMap.generation','生成中')},
                25: {color: 'blue', text: this.i18n('statusMap.generation1','生成中25%')},
                50: {color: 'blue', text: this.i18n('statusMap.generation2','生成中50%')},
                75: {color: 'blue', text: this.i18n('statusMap.generation3','生成中75%')},
                100: {color: 'green', text: this.i18n('statusMap.success','生成成功')},
            },
        }
    },
    methods: {
        i18n(name,text,key){
            return this.$ti18(name,text,"FormExcelGenTask",key);
        },
        getRemark(record){
            if(record.remark){
                return record.remark;
            }
            return "";
        },
        delById(ids) {
            return FormExcelGenTaskApi.del({ids: ids.join(',')});
        },
        getListByParams(parameter) {
            return FormExcelGenTaskApi.query(parameter)
        },
        downloadExcel(record){
            var accessToken = TokenUtil.getToken();
            var url=`/api/api-system/system/core/sysFile/download/${record.fileId}?accessToken=`+ accessToken;
            window.open(url);
            FormExcelGenTaskApi.downloadRecord({genTaskId:record.id});
        },
        getDownloadRecord(record){
            this.selectGenTaskId="";
            this.$set(this,);
            this.visible=true;
            this.selectGenTaskId=record.id;
        },
        onClose(){
            this.visible=false;
        }

    }
}
</script>
<style scoped>

</style>

